package com.congee02.dbservlet.utils;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public final class ResponseUtils {

    private ResponseUtils() {
    }

    public static void writeJsonAndClose(HttpServletResponse resp, Object data) throws IOException {
        resp.setContentType("application/json");
        resp.setCharacterEncoding("UTF-8");
        try (final PrintWriter out = resp.getWriter()) {
            out.write(JsonUtils.object2Json(data));
        }
    }

}
